package com.woniuxy01;


class FatherClass {
    public void test() {
        System.out.println("FatherClass---test");
    }
}

class SonClass extends FatherClass {
    //多态三步1---重写
    public void test() {
        System.out.println("SonClass---test");
    }
}

public class Test05 {
    public static void main(String[] args) {
        Animal[] animals = new Animal[2];
        animals[0] = new Cat("cat1", 1, 100);
        animals[1] = new Dog("dog", 2, 99);
        Feeder feeder = new Feeder();
        for(Animal animal : animals) {
            feeder.feed(animal);
        }
    }

    private static void test03() {
        //对象数组，数组中存储2个动物
        Animal[] animals = new Animal[2];
        animals[0] = new Cat("cat1", 1, 100);
        animals[1] = new Dog("dog", 2, 99);
        for (Animal animal : animals) {
            System.out.println(animal.toString());
        }
    }

    private static void test02() {
        FatherClass fc = new FatherClass();
        SonClass sc = new SonClass();
        //多态三步2---子类赋值给父类
        fc = sc;
        //多态三步3---通过父类对象调方法，执行的是子类的方法
        fc.test();
    }

    private static void test01() {
        FatherClass fc = new FatherClass();
        SonClass sc = new SonClass();
        //父类对象，执行父类方法
        fc.test();
        //子类对象，执行子类方法
        sc.test();
    }
}
